#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
int main()
{
 umask(0);
//int fd1=open("log1.txt",O_RDONLY|O_CREAT,0666);
//
//int fd2=open("log2.txt",O_RDONLY|O_CREAT,0666);
//int fd3=open("log3.txt",O_RDONLY|O_CREAT,0666);
//int fd4=open("log4.txt",O_RDONLY|O_CREAT,0666);
//int fd5=open("log5.txt",O_RDONLY|O_CREAT,0666);
//
//printf("fd1:%d\n",fd1);
//
//printf("fd2:%d\n",fd2);
//printf("fd3:%d\n",fd3);
//printf("fd4:%d\n",fd4);
//printf("fd5:%d\n",fd5);
/*  int fd=open("log.txt",O_WRONLY|O_CREAT,0666);
  if(fd<0)
  {
    perror("open");
    return 1;
  }

  const char* str="hello test\n";
  for(int i=0;i<5;i++)
  {
    write(fd,str,strlen(str));
  }

  close(fd);*/

/* int fd=open("log.txt",O_RDONLY);
 if(fd<0)
 {
   perror("open");
   return 1;
 }
 char buf[55];
 read(fd,buf,55);
 printf(buf);*/

/* close(1);
 int fd = open("log.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
 if(fd<0)
 {
   perror("open");
   return 1;
 }

 printf("hello ff\n");
 printf("hello ff\n");
 printf("hello ff\n");
 printf("hello ff\n");
 printf("hello ff\n");
 printf("hello ff\n");
fflush(stdout);
 close(fd);*/

 /*
 close(0);
int fd=open("log.txt",O_RDONLY|O_CREAT,0666);
if(fd<0)
{
  perror("open");
  return 1;
}

char str[40];
while(scanf("%s",str)!=EOF)
{
  printf("%s\n",str);
}

close(fd);*/

/* printf("hello printf\n");
 perror("perror");

 
  fprintf(stdout, "stdout:hello fprintf\n"); //stdout
  fprintf(stderr, "stderr:hello fprintf\n"); //stderr      */

 int fd = open("log.txt", O_WRONLY | O_CREAT, 0666);
	if (fd < 0){
		perror("open");
		return 1;
	}
//	close(1);
	dup2(fd, 1);
	printf("hello printf\n");
	fprintf(stdout, "hello fprintf\n");
  return 0;
}

